package com.muyu.danmo.service.impl;


import com.muyu.common.core.domain.Result;
import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.common.system.domain.LoginUser;
import com.muyu.danmo.domain.DanmoInformationCopy1;
import com.muyu.danmo.domain.DanmoUserVisitors;
import com.muyu.danmo.mapper.DanmoInformationCopy1Mapper;
import com.muyu.danmo.mapper.DanmoUserVisitorsMapper;
import com.muyu.danmo.service.IDanmoUserVisitorsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 访客Service业务层处理
 * 
 * @author yangle
 * @date 2024-11-15
 */
@Service
public class DanmoUserVisitorsServiceImpl implements IDanmoUserVisitorsService
{
    @Autowired
    private DanmoUserVisitorsMapper danmoUserVisitorsMapper;

    @Autowired
    private DanmoInformationCopy1Mapper danmoInformationCopy1Mapper;
    /**
     * 查询访客
     * 
     * @param visitorId 访客主键
     * @return 访客
     */
    @Override
    public DanmoUserVisitors selectDanmoUserVisitorsByVisitorId(Long visitorId)
    {
        return danmoUserVisitorsMapper.selectDanmoUserVisitorsByVisitorId(visitorId);
    }

    /**
     * 查询访客列表
     * 
     * @param danmoUserVisitors 访客
     * @return 访客
     */
    @Override
    public List<DanmoUserVisitors> selectDanmoUserVisitorsList(DanmoUserVisitors danmoUserVisitors)
    {
        return danmoUserVisitorsMapper.selectDanmoUserVisitorsList(danmoUserVisitors);
    }

    /**
     * 新增访客
     * 
     * @param danmoUserVisitors 访客
     * @return 结果
     */
    @Override
    public Result insertDanmoUserVisitors(DanmoUserVisitors danmoUserVisitors)
    {
        try {
            int i = danmoUserVisitorsMapper.insertDanmoUserVisitors(danmoUserVisitors);
            return Result.success(i,"添加成功");
        }catch (Exception e){
            return Result.error("添加失败");
        }

    }

    /**
     * 修改访客
     * 
     * @param danmoUserVisitors 访客
     * @return 结果
     */
    @Override
    public Result updateDanmoUserVisitors(DanmoUserVisitors danmoUserVisitors)
    {
        int i = danmoUserVisitorsMapper.updateDanmoUserVisitors(danmoUserVisitors);
        return Result.success(i,"修改成功");
    }

    /**
     * 批量删除访客
     * 
     * @param visitorIds 需要删除的访客主键
     * @return 结果
     */
    @Override
    public Result deleteDanmoUserVisitorsByVisitorIds(Long[] visitorIds)
    {
        int i = danmoUserVisitorsMapper.deleteDanmoUserVisitorsByVisitorIds(visitorIds);
        return Result.success(i,"删除成功");
    }

    /**
     * 删除访客信息
     * 
     * @param visitorId 访客主键
     * @return 结果
     */
    @Override
    public Result deleteDanmoUserVisitorsByVisitorId(Long visitorId)
    {
        int i = danmoUserVisitorsMapper.deleteDanmoUserVisitorsByVisitorId(visitorId);
        return Result.success(i,"删除成功");
    }

    @Override
    public List<DanmoUserVisitors> selectDanmoUserList() {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        Long userid = loginUser.getUserid();
        DanmoUserVisitors danmoUserVisitors = new DanmoUserVisitors();
        danmoUserVisitors.setUserId(userid);
        List<DanmoUserVisitors> danmoUserVisitorsList = danmoUserVisitorsMapper.selectDanmoUserVisitorsList(danmoUserVisitors);
        for (DanmoUserVisitors userVisitors : danmoUserVisitorsList) {
            DanmoInformationCopy1 danmoInformationCopy1List=  danmoInformationCopy1Mapper.selectInforCopy(userVisitors.getInformationId(), userVisitors.getTableName());
            userVisitors.setDanmoInformationCopy1List(danmoInformationCopy1List);
        }
        return danmoUserVisitorsList;
    }
}
